package com.itheima.a12.test0;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @ClassName A
 * @Description TODO
 * @Author tant
 * @Date 2025/5/21 15:45
 */
public class A {

    interface Foo {
        void foo() ;

        int bar();
    }

    static class Target implements Foo {
        public void foo() {
            System.out.println("Target.foo");
        }

        @Override
        public int bar() {
            System.out.println("Target.bar");
            return 100;
        }
    }

    interface InvocationHandler {
        Object invoke(Object proxy,Method foo, Object[] args) throws InvocationTargetException, IllegalAccessException;
    }

    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        Foo $Proxy0 = new $Proxy0(new InvocationHandler() {
            @Override
            public Object invoke(Object proxy,Method method, Object[] args) throws InvocationTargetException, IllegalAccessException {
                //1 增强
                System.out.println("before...");

                //2 调用目标
                return method.invoke(new Target(), args);


            }
        });
        $Proxy0.foo();
        $Proxy0.bar();
    }
}

    